#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int n;
string op,ip;
struct comp{
	string ipad;
	int aa;
}server[1023];
int svlen=0;
bool check(string);
int main(){
	//freopen("network.in","r",stdin);
	//freopen("network.out","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>op>>ip;
		if(!(check(ip))){
			cout<<"ERR"<<endl;
			continue;
		}
		
		if(op=="Server"){
			bool flag=true;
			for(int i=0;i<svlen;i++){
				if(server[i].ipad==ip){
					cout<<"FAIL"<<endl;
					flag=false;
					break;
				}
			}
			if(!flag)
				continue;
			server[svlen++].ipad=ip;
			server[svlen-1].aa=i+1;
			cout<<"OK"<<endl;
		}
		if(op=="Client"){
			bool flag=true;
			for(int i=0;i<svlen;i++){
				if(server[i].ipad==ip){
					cout<<server[i].aa<<endl;
					flag=false;
					break;
				}
			}
			if(!flag)
				continue;
			cout<<"FAIL"<<endl; 
		}
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

bool check(string aa){
	aa+='.';
	int a[5];
	memset(a,sizeof(a),0);
	int aalen=0;
	bool numbering;
	int lene = 0;
	int zz=0;
	int dots=0;
	int fenhao=0;
	for(int i=0;i<aa.length();i++){
		if(aa[i]=='.'){
			//cout<<zz<<endl;
			dots++;
			if(dots>4)
				return false;
			a[aalen++]=zz;
			if(zz==0&&lene!=1){			
			//cout<<'f'<<lene<<endl;
				return false;
			}
			if(zz!=0)
				if(pow(10,lene-1)>zz)
					return false;
			zz=lene=0;
			continue;
		}
		if(aa[i]==':'){
			//cout<<zz<<endl;
			fenhao++;
			if(fenhao>2)
				return false;
			a[aalen++]=zz;
			if(zz==0&&lene!=1){			
			//cout<<'f'<<lene<<endl;
				return false;
			}
			if(pow(10,lene-1)>zz)
				return false;
			zz=lene=0;
			continue;
		}
		if((aa[i]<='9')&&(aa[i]>='0')){
			lene++;
			zz=zz*10+(aa[i]-'0');
		}
	}
	//cout<<'l'<<a[4];
	if((fenhao==1)&&(dots==4))
	if(a[0]>=0&&a[0]<=255)
	if(a[1]>=0&&a[1]<=255)
	if(a[2]>=0&&a[2]<=255)
	if(a[3]>=0&&a[3]<=255)
	if(a[4]>=0&&a[4]<=65535)
	return true;
	return false;
}
